package modelo.bean;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonManagedReference;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.ForeignKey;

@XmlRootElement
@Entity
public class Disciplina implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	private String nome;
	
	@OneToMany(mappedBy ="disciplina")
	@Fetch(FetchMode.JOIN)
	@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
	private List<Topico> listaDeTopicos;
	
	@ManyToOne
	@Fetch(FetchMode.JOIN)
	@ForeignKey(name="fk_professor")
	@JoinColumn(name = "professor_id", referencedColumnName = "idprofessor", nullable=false)  
	private Professor professor;
	
	private String semestre;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	@JsonManagedReference("disciplina-topico")
	public List<Topico> getListaDeTopicos() {
		return listaDeTopicos;
	}

	public void setListaDeTopicos(List<Topico> listaDeTopicos) {
		this.listaDeTopicos = listaDeTopicos;
	}

	@JsonBackReference("professor-disciplina")
	public Professor getProfessor() {
		return professor;
	}

	public void setProfessor(Professor professor) {
		this.professor = professor;
	}

	public String getSemestre() {
		return semestre;
	}

	public void setSemestre(String semestre) {
		this.semestre = semestre;
	}
}
